#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import xmlrpclib

url='http://127.0.0.1:8069'
db='Test'
username='admin'
password='1'


# 连接信息
# xmlrpc/2/common
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
common.version()

# 用户权限认证
uid = common.authenticate(db, username, password, {})

# 调用方法
# xmlrpc/2/object
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))


def exec_with_json(json):
    return models.execute_kw(db, uid, password,
      json['model'], json['method'],
      json['args'], json['kwargs'])
context = {
      'lang': 'zh_CN',
      'tz': 'Asia/Shanghai',
      'uid': 1,
      'params': {
        'action': 358,
        'page': 0,
        'limit': 80,
        'view_type': 'list',
        'model': 'stock.move',
        'menu_id': 285,
        '_push_me': False
      },
      'group_by': 'product_id'
    }
json = {
  'model': 'stock.move',
  'method': 'read_group',
  'args': [
  ],
  'kwargs': {
    'groupby': [
      'product_id'
    ],
    'fields': [
      'product_id',
      'picking_id',
      'picking_type_id',
      'product_uom_qty',
      'location_id',
      'location_dest_id',
      'date',
      'date_expected',
    ],
    'domain': [
      ['picking_type_id',
      'ilike',
      '送货单'],
      [
        'state',
        'in',
        [
          'assigned',
          'confirmed',
          'waiting'
        ]
      ]
    ],
    'context': {
      'lang': 'zh_CN',
      'tz': 'Asia/Shanghai',
      'uid': 1,
      'params': {
        'action': 358,
        'page': 0,
        'limit': 80,
        'view_type': 'list',
        'model': 'stock.move',
        'menu_id': 285,
        '_push_me': False
      },
      'group_by': 'product_id'
    },
    'offset': 0,
    'lazy': True,
    'limit': False,
    'orderby': False
  }
}


get_todo_list_json = {
  'model': 'stock.move',
  'method': 'get_todo_list',
  'args':[],
  'kwargs':{'picking_type_id':2,'context':context}
}
print(exec_with_json(get_todo_list_json))

